import http from './index'

/** 首页
 * 获取首页列表
 */
function getArticleList(params) {
	return new Promise((resolve, reject) => {
		http('post', '/articles/articleList', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}


/**首页顶部
 * 搜索
 */
function search(params) {
	return new Promise((resolve, reject) => {
		http('post', '/articles/search', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

/**首页顶部
 * 登录
 */
function login(params) {
	return new Promise((resolve, reject) => {
		http('post', '/users/login', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

/**文章详细页/编辑文章
 * 获取文章详情
 */
 function getArticlesDetail(params) {
	return new Promise((resolve, reject) => {
		http('post', '/articles/detail', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

/**文章详细页
 * 获取继续阅读列表
 */
function getKeepList(params) {
	return new Promise((resolve, reject) => {
		http('post', '/articles/keepList', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

/**文章详细页
 * 获取上下一篇列表
 */
function nextPreList(params) {
	return new Promise((resolve, reject) => {
		http('post', '/articles/nextPreList', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}
/**文章右侧
 * 获取随机文章
 */
function radomArticle(params) {
	return new Promise((resolve, reject) => {
		http('post', '/articles/radomArticle', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

/**文章详细页
 * 获取评论列表
 */
function getCommentList(params) {
	return new Promise((resolve, reject) => {
		http('post', '/comments/commentList', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

/**文章详细页
 * 新增评论
 */
function postComments(params) {
	return new Promise((resolve, reject) => {
		http('post', '/comments/postComments', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

/**文章详细页
 * 新增回复
 */
function postRelay(params) {
	return new Promise((resolve, reject) => {
		http('post', '/comments/postRelay', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}


/**我的模块
 * 新增/修改/删除1级分类
 */
function changeTypes1(params) {
	return new Promise((resolve, reject) => {
		http('post', '/classtypes/change1', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

/**我的模块
 * 新增/修改/删除2级分类
 */
function changeTypes2(params) {
	return new Promise((resolve, reject) => {
		http('post', '/classtypes/change2', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}



/**我的模块
 * 新增/修改/删除链接分类
 */
 function addLinkType1(params) {
	return new Promise((resolve, reject) => {
		http('post', '/links/change1', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}
/**我的模块
 * 新增/修改/删除链接
 */
 function addLinkType2(params) {
	return new Promise((resolve, reject) => {
		http('post', '/links/change2', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

/**我的模块
 * 查询链接
 */
 function getLinks(params) {
	return new Promise((resolve, reject) => {
		http('get', '/links/list', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}



/**我的模块
 * 查询文章分类
 */
 function getClasstypes(params) {
	return new Promise((resolve, reject) => {
		http('get', '/classtypes/list', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

/** 我的
 * 获取文章列表--【后台】
 */
 function articleListBack(params) {
	return new Promise((resolve, reject) => {
		http('post', '/articles/articleListBack', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}
/** 我的
 * 新增文章--【后台】
 */
 function postAricle(params) {
	return new Promise((resolve, reject) => {
		http('post', '/articles/postAricle', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}
/** 我的
 * 删除文章--【后台】
 */
 function deleteArticle(params) {
	return new Promise((resolve, reject) => {
		http('post', '/articles/delete', params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

//通用--上传图片
function uploadImg(params,header) {
	return new Promise((resolve, reject) => {
		http('post', '/imgs/uploadImg', header,params).then(
			(res) => {
				resolve(res)
			},
			(error) => {
				reject(error)
			}
		)
	})
}

//

export {
	search,
	getClasstypes,
	getArticleList,
	getKeepList,
	getCommentList,
	postComments,
	postRelay,
	changeTypes1,
    changeTypes2,
	login,
    articleListBack,
    getArticlesDetail,
    postAricle,
    deleteArticle,
    uploadImg,
    addLinkType1,
    addLinkType2,
    getLinks,
    nextPreList,
    radomArticle
}
